<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // ES5 给函数的参数设置默认值
    // a = a == undefined ? 默认值 : a;
    // a = a || 默认值;
    // function sum(a,b){
    //     // 给形参a b 设置默认值 (判断赋值)
    //     // a = a == undefined ? 0 : a;
    //     // b = b == undefined ? 0 : b;

    //     a = a || 0;   // a = a ? a : 0;
    //     b = b || 0;   // a = a ? a : 0;

    //     console.log("参数a,b:",a,b);

    //     return a + b;
    // }


    // ES6  函数参数的默认值
    function sum(a = 0,b = 0){  // 给形参a b 设置默认值
        // 等价于:
        // a = a == undefined ? 0 : a;
        // b = b == undefined ? 0 : b;

        console.log("参数a,b:",a,b);
        return a + b;
    }

    var result = sum(10,20);
    console.log(result);


    var result = sum();
    console.log(result);

    var result = sum(undefined,null);
    console.log(result);

</script>
</html>